import { _decorator, Component, director, Node, Sprite } from 'cc';
import { emits } from '../data/enums';
import { nodePool } from '../utils/nodePool';
import { gameConfig } from '../data/gameConfig';
import { audioTool } from '../utils/audioTool';
import { loadRes } from '../utils/loadRes';
const { ccclass, property } = _decorator;

@ccclass('pause')
export class pause extends Component {
    @property(Sprite)
    musicBtn: Sprite = null;
    protected onEnable(): void {
        director.emit(emits.banKey);
        this.init();
    }

    goHome() {
        
        director.loadScene("main");
    }
    init(){
        if(gameConfig.isBgm){
            this.musicBtn.spriteFrame = loadRes.ins.getSpriteFrame("musicOn");
        }else{
            this.musicBtn.spriteFrame = loadRes.ins.getSpriteFrame("musicOff");
        }
    }
    continue() {
        director.emit(emits.enAbleKey);
        nodePool.ins.huiShouNode(this.node);
    }
    clickLevelView() {
        nodePool.ins.getPoolNode("levelView", this.node);
    }
    clickMusic() {
        gameConfig.isBgm = !gameConfig.isBgm;
        if (gameConfig.isBgm) {
            audioTool.ins.playMusic("bgm");
            this.musicBtn.spriteFrame = loadRes.ins.getSpriteFrame("musicOn");
        } else {
            audioTool.ins.stopMusic();
            this.musicBtn.spriteFrame = loadRes.ins.getSpriteFrame("musicOff");
        }

    }
}


